// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import '@/assets/css/reset.css'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import { Message } from 'element-ui/packages/message/index'
import router from './router/index'
import request from './utils/request' // 封装错误
import axios from 'axios'
import echarts from 'echarts'
import switchFunc from './utils/switchFunc'
import getGlobal from './utils/common'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// import '@/assets/js/dynamic.js'

Vue.config.productionTip = false

Vue.use(ElementUI)
/* eslint-disable no-new */
Vue.prototype.$getGlobal=getGlobal
Vue.prototype.$echarts=echarts
Vue.prototype.$axios=axios
for(let key in request){
  window[key]=request[key]
}
for(let key in switchFunc){
  Vue.filter(key, switchFunc[key])
}

NProgress.configure({showSpinner:false})

router.beforeEach((to,from,next) => {
  NProgress.start()
  if(to.fullPath==='/login'){
    next()
  }else{
    if(getGlobal.getCookie('Token')){
      next()
    }else{
      ElementUI.Message({
        type:'error',
        message:'对不起，请先登录'
      })
      next('/login')
    }
  }
  // if(to.matched.some(item => item.meta.auth)){
  //   router.back(-1)
  //   next()
  // }else{
  //   next()
  // }
})
router.afterEach((to,from,next) => {
  document.title=to.name
  NProgress.done()
})

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
